package com.ifast.experts.controller;

import com.ifast.common.utils.DateUtils;
import com.ifast.experts.domain.TreeNode;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ifast.common.base.AdminBaseController;
import com.ifast.experts.domain.ExpertExpertsInfoDO;
import com.ifast.experts.service.ExpertExpertsInfoService;
import com.ifast.common.utils.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 *
 * <pre>
 *
 * </pre>
 * <small> 2018-12-05 12:02:33 | JimmyMo</small>
 */
@Controller
@RequestMapping("/experts/expertExpertsInfo")
public class ExpertExpertsInfoController extends AdminBaseController {

    @Autowired
    private ExpertExpertsInfoService expertExpertsInfoService;

    @GetMapping()
    @RequiresPermissions("experts:expertExpertsInfo:expertExpertsInfo")
    String ExpertExpertsInfo(Model model){
        return "experts/expertExpertsInfo/expertExpertsInfo";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("experts:expertExpertsInfo:expertExpertsInfo")
    public Result<Page<ExpertExpertsInfoDO>> list(HttpServletRequest request){
        String searchName = request.getParameter("searchName");
        String shztValue = request.getParameter("shztValue");
        // 查询列表数据
        Wrapper<ExpertExpertsInfoDO> wrapper = new EntityWrapper<ExpertExpertsInfoDO>();
        //wrapper.and("1=1");
        //wrapper.eq("removeFlag", "0");
        if(StringUtils.isNotBlank(searchName)){
            wrapper.like("concat(name,idcard,phone)",searchName);//多字段模糊匹配
        }
        if(StringUtils.isNotBlank(shztValue)){
            wrapper.eq("status",shztValue);//多字段模糊匹配
        }

        /******排序相关********/
        String sortName = request.getParameter("sortName");
        String sortOrder = request.getParameter("sortOrder");
        if(StringUtils.isNotBlank(sortName)){
            if("usertypeView".equals(sortName)){
                wrapper.orderBy("usertype","asc".equals(sortOrder));
            }else if("unit".equals(sortName)){
                wrapper.orderBy("unitid","asc".equals(sortOrder));
            }else{
                wrapper.orderBy(sortName,"asc".equals(sortOrder));
            }
        }

        Page<ExpertExpertsInfoDO> page = expertExpertsInfoService.selectPage(getPage(ExpertExpertsInfoDO.class), wrapper);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        for (int i = 0; i < page.getRecords().size(); i++) {
            page.getRecords().get(i).setBirthdayStr(DateUtils.format(page.getRecords().get(i).getBirthday()));
            if (page.getRecords().get(i).getTraintime() != null){
                page.getRecords().get(i).setTraintimeStr(DateUtils.format(page.getRecords().get(i).getTraintime()));
            }
            if (page.getRecords().get(i).getGender().equals("1")){
                page.getRecords().get(i).setGender("男");
            }else if (page.getRecords().get(i).getGender().equals("2")) {
                page.getRecords().get(i).setGender("女");
            }else{
                page.getRecords().get(i).setGender("未知性别");
            }
        }
        return Result.ok(page);
    }

    @GetMapping("/add")
    @RequiresPermissions("experts:expertExpertsInfo:add")
    String add(Model model,HttpServletRequest request){
        String name = request.getParameter("name");
        String idcard = request.getParameter("idcard");
        model.addAttribute("pageType", "save");
        ExpertExpertsInfoDO expertExpertsInfo = new ExpertExpertsInfoDO();
        expertExpertsInfo.setIdcard(idcard);
        expertExpertsInfo.setName(name);
        model.addAttribute("expertExpertsInfo", expertExpertsInfo);
        return "experts/expertExpertsInfo/edit";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("experts:expertExpertsInfo:edit")
    String edit(@PathVariable("id") Integer id,Model model){
        model.addAttribute("pageType", "update");
        ExpertExpertsInfoDO expertExpertsInfo = expertExpertsInfoService.selectById(id);
        model.addAttribute("expertExpertsInfo", expertExpertsInfo);
        return "experts/expertExpertsInfo/edit";
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("experts:expertExpertsInfo:add")
    public Result<String> save( ExpertExpertsInfoDO expertExpertsInfo){
        expertExpertsInfo.setTimecreated(new Date());
        expertExpertsInfo.setTimelastmodified(new Date());
        expertExpertsInfo.setUpdateTime(new Date());
        expertExpertsInfo.setPassword("123456");
        expertExpertsInfo.setCode(expertExpertsInfo.getIdcard());
        expertExpertsInfoService.insert(expertExpertsInfo);
        return Result.ok();
    }
    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("experts:expertExpertsInfo:edit")
    public Result<String>  update( ExpertExpertsInfoDO expertExpertsInfo){
        if (expertExpertsInfo.getStatus() == null){
            expertExpertsInfo.setStatus("0");
        }
        expertExpertsInfo.setTimelastmodified(new Date());
        expertExpertsInfo.setUpdateTime(new Date());
        expertExpertsInfoService.updateById(expertExpertsInfo);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping( "/remove")
    @ResponseBody
    @RequiresPermissions("experts:expertExpertsInfo:remove")
    public Result<String>  remove( Integer id){
        expertExpertsInfoService.deleteById(id);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping( "/batchRemove")
    @ResponseBody
    @RequiresPermissions("experts:expertExpertsInfo:batchRemove")
    public Result<String>  remove(@RequestParam("ids[]") Integer[] ids){
        //expertExpertsInfoService.deleteBatchIds(Arrays.asList(ids));
        if (ids != null && ids.length > 0) {
            for (Integer id : ids) {
                expertExpertsInfoService.deleteById(id);
            }
        }
        return Result.ok();
    }

    /**
     * 批量导出
     */
    @GetMapping( "/exportExcel")
    @ResponseBody
    @RequiresPermissions("experts:expertExpertsInfo:add")
    public Result<String>  exportExcel(HttpServletRequest request , HttpServletResponse response){
        //excel表头
        String title[] = new String[] {
                "姓名","性别","身份证","生日","学历","治政面貌","毕业学校","专业","专技职务","专技职务学科",
                "教师资格证号","教师资格类型","教师资格任教学科","认定机构","现任教学段","现任教学科","是否特级教师","行政职务","工作单位","工作单位地址",
                "工作单位邮编","工作单位电话","家庭地址","家庭邮编","家庭电话","邮箱","手机","推荐类别","科目","师教等级",
                "学校等级","是否培训","培训时间","活动次数","工作经验","所属区域","推荐级别","银行卡1类别","银行卡1号码","银行卡2类别",
                "银行卡2号码","审核状态","培训状态"
        };

        //1.按照创建时间排序，获取需要导出的数据
        Wrapper<ExpertExpertsInfoDO> wrapper = new EntityWrapper<ExpertExpertsInfoDO>();
        wrapper.orderBy("timeCreated","asc".equals("asc"));
        Page<ExpertExpertsInfoDO> page = expertExpertsInfoService.selectPage(getPage(ExpertExpertsInfoDO.class), wrapper);
        //2.生成Excel
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet("专家信息");
        HSSFRow row = sheet.createRow(0);
        HSSFCell cell = null;
        for(int i=0;i<title.length;i++){
            cell = row.createCell(i);
            cell.setCellValue(title[i]);
        }

        List<ExpertExpertsInfoDO> res = page.getRecords();
        //3.封装Excel数据
        if(res.size() > 0){
            for (int i = 0; i < res.size() ; i++) {
                ExpertExpertsInfoDO thisBean = res.get(i);
                if(thisBean.getIssuper().equals("1")){
                    thisBean.setIssuper("是");
                }else{
                    thisBean.setIssuper("否");
                }
                if(thisBean.getIstrain().equals("1")){
                    thisBean.setIstrain("是");
                }else{
                    thisBean.setIstrain("否");
                }
                if(thisBean.getGender().equals("1")) {
                    thisBean.setGender("男");
                }else if (thisBean.getGender().equals("2")){
                    thisBean.setGender("女");
                }else{
                    thisBean.setGender("未知性别");
                }
                if (thisBean.getStatus().equals("0")){
                    thisBean.setStatus("待审核");
                }else if (thisBean.getStatus().equals("1")){
                    thisBean.setStatus("审核通过");
                }else if (thisBean.getStatus().equals("2")){
                    thisBean.setStatus("审核不通过");
                }else {

                }

                HSSFRow thisRow = sheet.createRow(i+1);
                HSSFCell thisCell = null;
//                Field[] fields = thisBean.getClass().getDeclaredFields();
//                for (int j = 0; j <fields.length ; j++) {
//                    String value = "";
//                    try {
//                        value = fields[i].get(thisBean).toString();
//                    } catch (IllegalAccessException e) {
//                        e.printStackTrace();
//                    }
//                    thisCell = row.createCell(j);
//                    cell.setCellValue(value);
//                }
                thisCell = thisRow.createCell(0);
                thisCell.setCellValue(thisBean.getName());

                thisCell = thisRow.createCell(1);
                thisCell.setCellValue(thisBean.getGender());

                thisCell = thisRow.createCell(2);
                thisCell.setCellValue(thisBean.getIdcard());

                thisCell = thisRow.createCell(3);
                thisCell.setCellValue(DateUtils.format(thisBean.getBirthday()));

                thisCell = thisRow.createCell(4);
                thisCell.setCellValue(thisBean.getRecord());

                thisCell = thisRow.createCell(5);
                thisCell.setCellValue(thisBean.getPolitical());

                thisCell = thisRow.createCell(6);
                thisCell.setCellValue(thisBean.getGraduated());

                thisCell = thisRow.createCell(7);
                thisCell.setCellValue(thisBean.getProfessional());

                thisCell = thisRow.createCell(8);
                thisCell.setCellValue(thisBean.getSpecialized());

                thisCell = thisRow.createCell(9);
                thisCell.setCellValue(thisBean.getSubject());

                thisCell = thisRow.createCell(10);
                thisCell.setCellValue(thisBean.getQualification());

                thisCell = thisRow.createCell(11);
                thisCell.setCellValue(thisBean.getQualificationtype());

                thisCell = thisRow.createCell(12);
                thisCell.setCellValue(thisBean.getTeachingsubjects());

                thisCell = thisRow.createCell(13);
                thisCell.setCellValue(thisBean.getAccreditingagencies());

                thisCell = thisRow.createCell(14);
                thisCell.setCellValue(thisBean.getThecurrentteaching());

                thisCell = thisRow.createCell(15);
                thisCell.setCellValue(thisBean.getNowteaching());

                thisCell = thisRow.createCell(16);
                thisCell.setCellValue(thisBean.getIssuper());

                thisCell = thisRow.createCell(17);
                thisCell.setCellValue(thisBean.getAdministrativeduties());

                thisCell = thisRow.createCell(18);
                thisCell.setCellValue(thisBean.getWorkunits());

                thisCell = thisRow.createCell(19);
                thisCell.setCellValue(thisBean.getWorkunitsaddress());

                thisCell = thisRow.createCell(20);
                thisCell.setCellValue(thisBean.getWorkunitszipcode());

                thisCell = thisRow.createCell(21);
                thisCell.setCellValue(thisBean.getWorkunitstel());

                thisCell = thisRow.createCell(22);
                thisCell.setCellValue(thisBean.getHomeaddress());

                thisCell = thisRow.createCell(23);
                thisCell.setCellValue(thisBean.getHomezipcode());

                thisCell = thisRow.createCell(24);
                thisCell.setCellValue(thisBean.getHometel());

                thisCell = thisRow.createCell(25);
                thisCell.setCellValue(thisBean.getEmail());

                thisCell = thisRow.createCell(26);
                thisCell.setCellValue(thisBean.getPhone());

                thisCell = thisRow.createCell(27);
                thisCell.setCellValue(thisBean.getCategory());

                thisCell = thisRow.createCell(28);
                thisCell.setCellValue(thisBean.getCourse());

                thisCell = thisRow.createCell(29);
                thisCell.setCellValue(thisBean.getLevel());

                thisCell = thisRow.createCell(30);
                thisCell.setCellValue(thisBean.getSchoollevel());

                thisCell = thisRow.createCell(31);
                thisCell.setCellValue(thisBean.getIstrain());

                thisCell = thisRow.createCell(32);
                thisCell.setCellValue(thisBean.getTraintime() == null?"":DateUtils.format(thisBean.getTraintime()));

                thisCell = thisRow.createCell(33);
                thisCell.setCellValue(thisBean.getExnumber());

                thisCell = thisRow.createCell(34);
                thisCell.setCellValue(thisBean.getWorkexperience());

                thisCell = thisRow.createCell(35);
                thisCell.setCellValue(thisBean.getAreaid());

                thisCell = thisRow.createCell(36);
                thisCell.setCellValue(thisBean.getRecommendstate());

                thisCell = thisRow.createCell(37);
                thisCell.setCellValue(thisBean.getBankcardtype1());

                thisCell = thisRow.createCell(38);
                thisCell.setCellValue(thisBean.getBankcardcode1());

                thisCell = thisRow.createCell(39);
                thisCell.setCellValue(thisBean.getBankcardtype2());

                thisCell = thisRow.createCell(40);
                thisCell.setCellValue(thisBean.getBankcardcode2());

                thisCell = thisRow.createCell(41);
                thisCell.setCellValue(thisBean.getStatus());

                thisCell = thisRow.createCell(42);
                thisCell.setCellValue(thisBean.getNettrainstatus());
            }
        }
        //4.返回数据
        OutputStream output= null;
        try {
            output = response.getOutputStream();
            response.reset();
            response.setHeader("Content-disposition", "attachment; filename=exportInfo.xls");
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Result.ok();
    }

    /**
     * 获取树形数据
     */
    @GetMapping( "/getTreeData/{type}")
    @ResponseBody
    public Result<List<TreeNode>>  getTreeData(@PathVariable("type") String type){
        Map<String,String> param = new HashMap<>();
        param.put("type",type);
        if (type.equals("graduateschool")){
            param.put("scIndex","1");
        }
        List<TreeNode> res = new ArrayList<>();
        List<TreeNode> list = expertExpertsInfoService.getDicList(param);
        if (list.size() > 0 && !type.equals("graduateschool")){
            res = expertExpertsInfoService.arrListToTree(list);
        }else {
            res = list;
        }
        return Result.ok(res);
    }

    @GetMapping("/importPage")
    public String importPage(Model model) {
        return "experts/expertExpertsInfo/importPage";
    }

    @PostMapping("/uploadFile")
    @ResponseBody
    public Result<String> uploadFile(@RequestParam("file") MultipartFile file) {
        try {
            if (file.getOriginalFilename().contains("xls") || file.getOriginalFilename().contains("XLS")){
                HSSFWorkbook wb = new HSSFWorkbook(file.getInputStream());
                HSSFSheet sheet = wb.getSheetAt(0);
                int rowCount = sheet.getLastRowNum() + 1;
                int columncount = sheet.getRow(0).getLastCellNum();
                if (rowCount >= 2){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    List<ExpertExpertsInfoDO> resList = new ArrayList<>();
                    for (int i = 1; i < rowCount; i++) {
                        HSSFRow row = sheet.getRow(i);
                        if (row !=null){
                            ExpertExpertsInfoDO data = new ExpertExpertsInfoDO();
                            for (int j = 0; j < columncount; j++) {
                                HSSFCell cell = row.getCell(j);
                                switch (j) {
                                    case 0:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据姓名不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据姓名不可为空");
                                        }
                                        data.setName(cell.getStringCellValue());
                                        break;
                                    case 1:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据性别不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据性别不可为空");
                                        }
                                        data.setGender(cell.getStringCellValue());
                                        break;
                                    case 2:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据身份证不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据身份证不可为空");
                                        }
                                        data.setIdcard(cell.getStringCellValue());
                                        break;
                                    case 3:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据生日不可为空");
                                        }
                                        if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
                                            data.setBirthday(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
                                        }else {
                                            cell.setCellType(Cell.CELL_TYPE_STRING);
                                            if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                                return Result.build(1,"第" + i + "条数据生日不可为空");
                                            }
                                            data.setBirthday(sdf.parse(cell.getStringCellValue()));
                                        }
                                        break;
                                    case 4:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据学历不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据学历不可为空");
                                        }
                                        data.setRecord(cell.getStringCellValue());
                                        break;
                                    case 5:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据政治面貌不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据政治面貌不可为空");
                                        }
                                        data.setPolitical(cell.getStringCellValue());
                                        break;
                                    case 6:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据毕业院校不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据毕业院校不可为空");
                                        }
                                        data.setGraduated(cell.getStringCellValue());
                                        break;
                                    case 7:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据专业不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据专业不可为空");
                                        }
                                        data.setProfessional(cell.getStringCellValue());
                                        break;
                                    case 8:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据专技职务不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据专技职务不可为空");
                                        }
                                        data.setSpecialized(cell.getStringCellValue());
                                        break;
                                    case 9:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据专技职务学科不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据专技职务学科不可为空");
                                        }
                                        data.setSubject(cell.getStringCellValue());
                                        break;
                                    case 10:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据教师资格证编号不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据教师资格证编号不可为空");
                                        }
                                        data.setQualification(cell.getStringCellValue());
                                        break;
                                    case 11:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据教师资格类型不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据教师资格类型不可为空");
                                        }
                                        data.setQualificationtype(cell.getStringCellValue());
                                        break;
                                    case 12:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据教师资格任教学科不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据教师资格任教学科不可为空");
                                        }
                                        data.setTeachingsubjects(cell.getStringCellValue());
                                        break;
                                    case 13:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据认定机构不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据认定机构不可为空");
                                        }
                                        data.setAccreditingagencies(cell.getStringCellValue());
                                        break;
                                    case 14:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据现任教学段不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据现任教学段不可为空");
                                        }
                                        data.setThecurrentteaching(cell.getStringCellValue());
                                        break;
                                    case 15:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据现任教学科不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据现任教学科不可为空");
                                        }
                                        data.setNowteaching(cell.getStringCellValue());
                                        break;
                                    case 16:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据是否特级教师不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据是否特级教师不可为空");
                                        }
                                        data.setIssuper(cell.getStringCellValue());
                                        break;
                                    case 17:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据行政职务不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据行政职务不可为空");
                                        }
                                        data.setAdministrativeduties(cell.getStringCellValue());
                                        break;
                                    case 18:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据工作单位不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据工作单位不可为空");
                                        }
                                        data.setWorkunits(cell.getStringCellValue());
                                        break;
                                    case 19:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据工作单位地址不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据工作单位地址不可为空");
                                        }
                                        data.setWorkunitsaddress(cell.getStringCellValue());
                                        break;
                                    case 20:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据工作单位邮编不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据工作单位邮编不可为空");
                                        }
                                        data.setWorkunitszipcode(cell.getStringCellValue());
                                        break;
                                    case 21:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据工作单位电话不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据工作单位电话不可为空");
                                        }
                                        data.setWorkunitstel(cell.getStringCellValue());
                                        break;
                                    case 22:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据家庭地址不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据家庭地址不可为空");
                                        }
                                        data.setHomeaddress(cell.getStringCellValue());
                                        break;
                                    case 23:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据家庭邮编不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据家庭邮编不可为空");
                                        }
                                        data.setHomezipcode(cell.getStringCellValue());
                                        break;
                                    case 24:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据家庭电话不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据家庭电话不可为空");
                                        }
                                        data.setHometel(cell.getStringCellValue());
                                        break;
                                    case 25:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据邮箱不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据邮箱不可为空");
                                        }
                                        data.setEmail(cell.getStringCellValue());
                                        break;
                                    case 26:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据手机不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据手机不可为空");
                                        }
                                        data.setPhone(cell.getStringCellValue());
                                        break;
                                    case 27:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据推荐类别不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据推荐类别不可为空");
                                        }
                                        data.setCategory(cell.getStringCellValue());
                                        break;
                                    case 28:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据科目不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据科目不可为空");
                                        }
                                        data.setCourse(cell.getStringCellValue());
                                        break;
                                    case 29:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据师教等级不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据师教等级不可为空");
                                        }
                                        data.setLevel(cell.getStringCellValue());
                                        break;
                                    case 30:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据学校等级不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据学校等级不可为空");
                                        }
                                        data.setSchoollevel(cell.getStringCellValue());
                                        break;
                                    case 31:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据是否培训不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据是否培训不可为空");
                                        }
                                        data.setIstrain(cell.getStringCellValue());
                                        break;
                                    case 32:
                                        if (cell == null || cell.equals("")){

                                        }else{
                                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
                                                data.setTraintime(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
                                            }else {
                                                cell.setCellType(Cell.CELL_TYPE_STRING);
                                                if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){

                                                }else {
                                                    data.setTraintime(sdf.parse(cell.getStringCellValue()));
                                                }
                                            }
                                        }
                                        break;
                                    case 33:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据活动次数不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据活动次数不可为空");
                                        }
                                        data.setExnumber(cell.getStringCellValue());
                                        break;
                                    case 34:
                                        if (cell != null && !cell.equals("")){
                                            cell.setCellType(Cell.CELL_TYPE_STRING);
                                            data.setWorkexperience(cell.getStringCellValue());
                                        }
                                        break;
                                    case 35:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据所属区域不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据所属区域不可为空");
                                        }
                                        data.setAreaid(cell.getStringCellValue());
                                        break;
                                    case 36:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据推荐类别不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据推荐类别不可为空");
                                        }
                                        data.setRecommendstate(cell.getStringCellValue());
                                        break;
                                    case 37:
                                        if (cell != null && !cell.equals("")){
                                            cell.setCellType(Cell.CELL_TYPE_STRING);
                                            data.setBankcardtype1(cell.getStringCellValue());
                                        }
                                        break;
                                    case 38:
                                        if (cell != null && !cell.equals("")){
                                            cell.setCellType(Cell.CELL_TYPE_STRING);
                                            data.setBankcardcode1(cell.getStringCellValue());
                                        };
                                        break;
                                    case 39:
                                        if (cell != null && !cell.equals("")){
                                            cell.setCellType(Cell.CELL_TYPE_STRING);
                                            data.setBankcardtype2(cell.getStringCellValue());
                                        }
                                        break;
                                    case 40:
                                        if (cell != null && !cell.equals("")){
                                            cell.setCellType(Cell.CELL_TYPE_STRING);
                                            data.setBankcardtype2(cell.getStringCellValue());
                                        }
                                        break;
                                    case 41:
                                        data.setStatus("0");
                                        break;
                                    case 42:
                                        if (cell == null || cell.equals("")){
                                            return Result.build(1,"第" + i + "条数据培训状态不可为空");
                                        }
                                        cell.setCellType(Cell.CELL_TYPE_STRING);
                                        if (cell.getStringCellValue() == null || cell.getStringCellValue().equals("")){
                                            return Result.build(1,"第" + i + "条数据培训状态不可为空");
                                        }
                                        data.setNettrainstatus(cell.getStringCellValue());
                                        break;
                                }
                            }
                            if (data.getGender().indexOf("男") != -1){
                                data.setGender("1");
                            }else if (data.getGender().indexOf("女") != -1){
                                data.setGender("2");
                            }else {
                                data.setGender("0");
                            }
                            if (data.getIstrain().equals("是")){
                                data.setIstrain("1");
                            }
                            if (data.getIssuper().equals("是")){
                                data.setIssuper("1");
                            }
                            if (data.getIstrain().equals("否")){
                                data.setIstrain("0");
                            }
                            if (data.getIssuper().equals("否")){
                                data.setIssuper("0");
                            }
                            data.setCode(data.getIdcard());
                            data.setUpdateTime(new Date());
                            data.setTimelastmodified(new Date());
                            data.setTimecreated(new Date());
                            data.setPassword("123456");
                            resList.add(data);
                        }
                    }
                    expertExpertsInfoService.insertBatch(resList);
                }else {
                    return Result.build(1,"导入文件数据为空");
                }
            }else {
                return Result.build(1,"导入文件格式错误");
            }
            return Result.ok();
        }catch (Exception e){
            return Result.build(1,"导入失败，请检查导入文件!" + e.getMessage());
        }
    }

}